﻿#region imports

using System.Configuration;
using System.Data.Services;
using System.Globalization;

#endregion

namespace Codeplex.ODataTFS.Web.Infrastructure
{
	public static class ConfigReader
	{
		public static string GetConfigValue(string key)
		{
			var value = string.Empty;

			value = ConfigurationManager.AppSettings[key];

			Validate(key, value);

			return value;
		}

		public static string GetWebConfigValue(string key)
		{
			var value = ConfigurationManager.AppSettings[key];

			Validate(key, value);

			return value;
		}

		private static void Validate(string key, string value)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				throw new DataServiceException(
					500,
					"Internal Server Error",
					string.Format(CultureInfo.InvariantCulture, "The '{0}' setting is not configured in the Web.config file", key),
					"en-US",
					null);
			}
		}
	}
}
